package com.dzt.cloudreader.activity;

import android.os.Handler;
import android.os.Message;
import android.widget.TextView;

import com.dzt.cloudreader.MainActivity;
import com.dzt.cloudreader.R;
import com.dzt.cloudreader.base.FrameActivity;

import butterknife.BindView;
import butterknife.OnClick;

public class SplashActivity extends FrameActivity {

	@BindView(R.id.tv_hint)
	TextView tvHint;
	private int count = 1;

	private Handler handler = new Handler(new Handler.Callback() {
		@Override
		public boolean handleMessage(Message msg) {
			switch (msg.what) {
				case 0:
					startActivity(MainActivity.class, null);
					finish();
					break;
				case 1:
					if (count == -1) {
						startActivity(MainActivity.class, null);
						finish();
						break;
					}
					tvHint.setText(count + "跳过");
					handler.sendEmptyMessageDelayed(1, 1000);
					count--;
					break;
				default:
					break;
			}
			return false;
		}
	});

	@Override
	protected int getLayoutId() {
		return R.layout.activity_splash;
	}

	@Override
	protected void initParams() {

	}

	@Override
	protected void onResume() {
		super.onResume();
		handler.sendEmptyMessageDelayed(1, 1000);
	}

	@OnClick(R.id.tv_hint)
	public void onViewClicked() {
		handler.removeMessages(1);
		handler.sendEmptyMessage(0);
	}
}
